<template>
	<view>
		<page-head :transparent='false'  :fixed="true">
			<slot slot="title">{{title.length>10?title.substr(0,10)+'...':title}}</slot>
			<slot slot="right"><span/></slot>
		</page-head>
		<view class="banner-row"><image src="../../static/img/sy/czg.jpg" mode="widthFix"></image></view>
		<brand-goods-list :goodsList="goodsList" :loadingText="loadingText" @eventClick="toGoodsDetail"></brand-goods-list>
	</view>
</template>

<script>
import BrandGoodsList from '../../components/brand-goods-list.vue';
let page = 1,
	pagesize = 20;
export default {
	components: {
		BrandGoodsList
	},
	data() {
		return {
			goodsList: [],
			loadingText: '加载中...',
			title:'超值购'
		};
	},
	onLoad(event) {
		if (event.token != '' && event.token != 'null' && event.token != null && event.token != undefined && event.token !=
		    'undefined') {
		    uni.setStorageSync('token', decodeURI(event.token));
		}
		page = 1;
		this.ti = '超值购';
		this.genList();
	},
	onReachBottom() {
		this.genList();
	},
	methods: {
		setTitle(title) {
			this.title=title;
			uni.setNavigationBarTitle({
				title: title
			});
		},
		async genList() {
			try {
				let data = { pageno: page, pagesize: pagesize };
				let res = await this.$request.post('/coupon-product/myq/tbGoods/qualityCouponGoods', { data: data });
				let datas = res.data;
				let newList = datas.data;
				if (newList != '' && newList.length > 0) {
					this.goodsList = this.goodsList.concat(newList);
					page++;
					if (page == 500 || newList.length < 19) {
						this.loadingText = '没有更多了';
					}
				} else {
					this.loadingText = '没有更多了';
				}
			} catch (e) {
				console.log(e);
				this.loadingText = '没有更多了';
			}
		},
		toGoodsDetail(e) {
			Date.prototype.toLocaleString = function() {
				return this.getFullYear() + '/' + (this.getMonth() + 1) + '/' + this.getDate();
			};
			let startTime = new Date(parseInt(e.coupon_start_time)).toLocaleString().substr(0, 9);
			let endTime = new Date(parseInt(e.coupon_end_time)).toLocaleString().substr(0, 9);
			h5NavigateTo({
				url:
					'../tbdetail/tbdetail?skuId=' +
					e.item_id +
					'&cid=0' +
					'&title=1' +
					'&seller=淘宝' +
					'&coupon_amount=' +
					e.coupon_amount +
					'&startTime=' +
					startTime +
					'&endTime=' +
					endTime +
					'&tm=false'
			});
		}
	}
};
</script>

<style lang="scss">
.banner-row {
	width: 100%;
	min-width: 750px;
	/* height: 150px; */
	image {
		width: 100%;
		height: 100%;
	}
}

</style>
